#!/usr/bin/env python

import sys
from wedewoba.app import BrowserApp

try:
    if len(sys.argv) == 1:
        sys.exit(0)

    url = sys.argv[1]

    app = BrowserApp()

    # define waht should be done whenn loading finishes
    def getData(result):
        if result:
            pix = app.browser.getElementImage().save("page_screenshot.png")       
            app.quit()
        else:
            raise RuntimeError("Could not load page")
            app.exit(1)

    # to run the 'getData' function
    # you can use either the 'loadFinished' signal
    app.browser.loadFinished.connect(getData)
    # or the 'onloadFinished' method
    #app.browser.onloadFinished = getData

    # run the app
    app.run(url)

except Exception as e:
    print e
